using System;
using System.Data.SqlClient;
using System.Data;
using Fan.Dongping.Common;

namespace Fan.Dongping.DataBase
{

    /// <summary>
    /// Data Access Base Class
    /// </summary>
    public class DA_Base
    {
        static SqlConnection sqlConn;

        static DA_Base()
        {
            sqlConn = new SqlConnection(Config.Instance.DatabaseConnectionString);
        }

        /// <summary>
        /// Run a sql,return a dataset
        /// </summary>
        /// <param name="cmdText"></param>
        /// <returns></returns>
        public static DataSet RunReturnDataset(string cmdText)
        {
            return SqlHelper.ExecuteDataset(sqlConn, CommandType.Text, cmdText);
        }

        /// <summary>
        /// run a sql, return a dataset
        /// </summary>
        /// <param name="cmdText"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public static DataSet RunReturnDataset(string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteDataset(sqlConn, CommandType.Text, cmdText, commandParameters);
        }

        public static SqlDataReader ExecuteReader(string cmdText)
        {
            return SqlHelper.ExecuteReader(sqlConn, CommandType.Text, cmdText);
        }

        public static SqlDataReader ExcuteReader(string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteReader(sqlConn, CommandType.Text, cmdText, commandParameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmdText"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteNonQuery(sqlConn, CommandType.Text, cmdText, commandParameters);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmdText"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string cmdText)
        {
            return SqlHelper.ExecuteNonQuery(sqlConn, CommandType.Text, cmdText);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmdText"></param>
        /// <returns></returns>
        public static object ExecuteScalar(string cmdText)
        {
            return SqlHelper.ExecuteScalar(sqlConn, CommandType.Text, cmdText);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmdText"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public static object ExecuteScalar(string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteScalar(sqlConn, CommandType.Text, cmdText, commandParameters);
        }
    }
}
